home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / dataval.exe / DATAVALD.TXT < prev    next >
Text File  |  1991-09-10  |  26KB  |  465 lines

  1. Data Validation Techniques
  2. In Turbo Vision
  3.  
  4.  
  5. by Danny Thorpe
  6.  
  7. presented at the 
  8. Borland Languages Conference
  9. April 1991
  10.  
  11.  
  12. Data Validation Techniques in Turbo Vision
  13. Turbo Vision, the new object-oriented event-driven application 
  14. framework introduced in Borland's Turbo Pascal 6.0, has generated quite 
  15. a bit of excitement in programming circles.  With Turbo Vision, 
  16. programmers finally have the tools and application framework necessary 
  17. to create programs that can truly benefit from the OOP methodology.  
  18. Programmers benefit from the variety of objects in Turbo Vision that can 
  19. be molded and extended into a multitude of application-specific dialog 
  20. boxes, windows, and other views.
  21. Turbo Vision is a multi-faceted environment.  At a superficial 
  22. level, it is a library of interrelated objects for managing the screen 
  23. display.  At another level, though, Turbo Vision is also an application 
  24. framework which defines a particular model of how a program should work, 
  25. both internally and visually.  It is this model and its framework 
  26. embodiment that provides the glue which ties the objects in the library 
  27. together into a functional society of objects.  A large portion of the 
  28. increased programmer productivity that can be realized with Turbo Vision 
  29. is due to this model as well:  the application framework you inherit 
  30. takes care of the actual mechanics of the program, so the programmer has 
  31. just to plug in modules and create cross-connections between objects.
  32. While many programmers appear to accept the code changes necessary 
  33. to move to Turbo Vision, some are reluctant to also embrace the 
  34. programming model that is an important part of Turbo Vision.  Without 
  35. this model, one can wind  up using Turbo  Vision objects in ways that 
  36. work against the grain of the programming model, creating unnecessary 
  37. complexity and frustration for the programmer.
  38. A large portion of any program involves feeding in data for the 
  39. program to operate on.  Traditional techniques for interactive data 
  40. entry are particularly difficult for programmers to give up when 
  41. learning Turbo Vision.  This paper will discuss some of the philosophy 
  42. behind Turbo Vision, the mechanics of various internal operations in 
  43. Turbo Vision, and why some of the old data entry techniques won't work 
  44. anymore.  Alternate approaches to data entry and validation more in line 
  45. with Turbo Vision model will be introduced and demonstrated.
  46.  
  47.  
  48. The Turbo Vision Model
  49. The Turbo Vision user interface is based upon the IBM System 
  50. Application Architecture, Common User Access specification.  CUA 
  51. provides guidelines that determined the behavior of the mouse, input 
  52. lines, push-buttons, and the choice of keys for particular actions, such 
  53. as Esc to cancel a dialog and Enter to select the default button of the 
  54. dialog.  
  55. A driving force in the Turbo Vision programming model is the idea 
  56. that the user of the program should be in control of the program at all 
  57. times.  Let the user do what he wants to do, within reason.  This 
  58. doesn't sound very remarkable at first, but when you consider how few 
  59. programs on the market allow the user this freedom, you begin to realize 
  60. that an unnecessary evil has been lurking in computer software: too many 
  61. restrictions are imposed upon the user by the program/programmer, to the 
  62. point that the software is in control of the user.
  63. Of course, a program needs structure in order to organize its 
  64. information into a meaningful form.  The user needs the information to 
  65. be structured, too, in order to understand the material.  The difficulty 
  66. comes in finding the fine line between the amount of structure needed by 
  67. the user and the amount of structure that begins to stifle the user with 
  68. unnecessary conditions and requirements.  Programs frequently wind up on 
  69. the stifling end of the scale simply because they're easier to write and 
  70. manage.  With traditional programming tools it is difficult to construct 
  71. a well-balanced, flexible program that considers all contingencies the 
  72. user may wish to embark upon.
  73. With Turbo Vision, you inherit a well-balanced, flexible program 
  74. architecture and then fill in the details of what your application is to 
  75. do.  At the lowest levels in the object hierarchy, Turbo Vision views 
  76. have the ability to be manipulated by the user in a multitude of ways.  
  77. But the programmer doesn't have to bend over backwards in Turbo Vision 
  78. to accomplish this user freedom.  All the programmer has to do is work 
  79. within the Turbo Vision model to extend the behavior of view objects 
  80. that already know how to interact with the user.
  81. The Turbo Vision model provides an environment based on autonomy 
  82. and independence.  The careful integration of OOP and event driven 
  83. programming provides the programmer with a rich set of tools and opens 
  84. doors to programming solutions nearly unattainable by traditional 
  85. methods.  Working in this model actually provides the programmer more 
  86. flexibility in expression and more opportunity to bring sophisticated 
  87. applications to completion than traditional programming tools can offer.
  88.  
  89.  
  90.  
  91. Traditional Validation Techniques
  92. As-You-Type Validation
  93. One method of ensuring an input field contains "clean" data is to 
  94. monitor each keystroke the user types.  Keys can be checked by position 
  95. within the input field if the validation is controlled by a template.  
  96. Formatting telephone number fields with a template like (999) 999-9999, 
  97. where '9' means 'accept any number in this position' is a common use of 
  98. as-you-type validation.  If a non-numeric key is pressed, the key 
  99. monitor can beep or provide some other non-intrusive indicator of an 
  100. error.  The other characters in the template can be treated just as 
  101. place-holders, so the user doesn't have to enter the parentheses for 
  102. every phone number, for example.
  103. As-you-type validation is good for position-sensitive formatting 
  104. of data, such as telephone numbers or dates, and for character 
  105. conversions, such as converting all characters entered in a field to 
  106. uppercase as they are typed.  As-you-type is difficult to use when 
  107. numbers or whole words need to be validated before being accepted, 
  108. because you don't really know what the user intends until the user is 
  109. finished typing, backspacing, and correcting misspellings.
  110. Templates are easy to implement in Turbo Vision:  make a 
  111. descendent of a TInputLine object and extend the HandleEvent method to 
  112. test each keystroke received by that view.  Acceptable keystrokes can be 
  113. passed to the inherited HandleEvent for default processing, and 
  114. unacceptable keys can be discarded with a beep and/or non-intrusive 
  115. error message.  
  116. As-You-Leave Validation
  117. Another opportunity to test the data is when the user moves the 
  118. cursor out of the field, presumably to the next field on the screen.  
  119. This method assumes that when the user hits the Tab key or Enter key to 
  120. move to the next field, the user is finished keying this field, and so 
  121. it is fair game for validation.  Validation is performed before the 
  122. program moves focus to the next field.  
  123. If the contents of the field are unacceptable, it is common for an 
  124. error message to be displayed, and the user is put back in the bad field 
  125. to reenter it.  This is where a poorly designed data entry system can be 
  126. really mean to the user - what if the user decides to cancel the whole 
  127. data entry operation?  It would be the job of every field to watch for a 
  128. particular "cancel" key, such as F1 or Esc, and shut down the data entry 
  129. mode when such a keystroke occurs.
  130. Data can be tested as the user leaves a field in Turbo Vision.  
  131. However, the traditional response of forcing the user back to a field 
  132. after the user has indicated he wants to go elsewhere conflicts with the 
  133. Turbo Vision model.  Consequently, this behavior is difficult to 
  134. implement in Turbo Vision, mainly because it requires different 
  135. assumptions about the user and environment than Turbo Vision assumes.  A 
  136. detailed explanation of the focus change mechanism is covered in the 
  137. next section.
  138. As-you-leave validation assumes that when the user leaves the